
use "$dir/data/outputs/ALPalldatafinal.dta", clear
keep if alpha2!=. & se12!=. & rho2!=. & se22!=.
rename se12 se_alpha2 
rename se11 se_alpha1
rename se21 se_rho1
rename se22 se_rho2

forval x = 1/2 {
gen t_alpha_fair`x' = abs(alpha`x' - 0.5)/se_alpha`x'
gen t_fairminded`x' = (t_alpha_fair`x'<=1.65)
gen t_alpha_self`x' = abs(alpha`x' - 1)/se_alpha`x'
gen t_selfish`x' = (t_alpha_self`x'<=1.28)
gen tempchange`x' = 1 if t_selfish`x'==1 & t_fairminded`x'==1
replace t_selfish`x' = 0 if tempchange`x'==1 
replace t_fairminded`x' = 0 if tempchange`x'==1
drop tempchange`x'
gen tstat_rho`x' = rho`x'/se_rho`x'
gen t_eff_focus`x' = (tstat_rho`x'>=1.28)
gen t_eq_focus`x' = (tstat_rho`x'<=-1.28)
gen t_intermediate`x' = t_eff_focus`x'==0 & t_eq_focus`x'==0
gen t_s_intermediate`x' = t_fairminded`x'==0 & t_selfish`x'==0 

}


gen flag = t_selfish1 ==1 | t_selfish2 ==1 




la var alpha1 "$\hat{\alpha}_n$ in 2013"
la var rho1 "$\hat{\rho}_n$ in 2013"

la var CCEI1  "CCEI in 2013"

eststo clear
** column 1:  dep var = alpha, specification = OLS, no controls

eststo: reg alpha2 alpha1, r


** column 2:  dep var = alpha, specification = OLS, controlling for rho and CCEI

eststo: reg alpha2 alpha1 rho1 CCEI1, r


** column 3:  dep var = rho, specification = OLS, no controls
global if if flag == 0 
eststo: reg rho2 rho1 $if, r


** column 4:  dep var = rho, specification = OLS, controlling for alpha and CCEI

eststo: reg rho2 alpha1 rho1 CCEI1 $if , r

esttab using "$dir/tables-and-figures/table3.tex", replace fragment booktabs wrap keep(alpha1 rho1 CCEI1 ) varwidth(25) star(* .1 ** .05 *** .01) label stats(N r2, label("Observations" "R-squared")) /// 
  se nomtitles numbers mgroups(" $\hat{\alpha}_n$ in 2016" "$\hat{\rho}_n$ in 2016", pattern(1 0 1 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) substitute(\_ _)

